output:
  html_document:
    number_sections: yes
    theme: cerulean
    toc: yes
    toc_depth: 5
    toc_float: yes
  pdf_document:
    toc: yes
    toc_depth: '5'

This will add a table of contents (toc) and will change the colors (theme: cerulean)

To find your favorite Rmarkdown theme: https://www.datadreaming.org/post/r-markdown-theme-gallery/

Day 1

R Markdown

This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.

When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.

R as a calculator

Comparing things

Variable

## Error: <text>:3:1: unexpected input
## 2: max.height #good
## 3: _
##    ^

packages

ggplot2 dplyr gapminder

Subset

by name

by logicals

combining logicals

CHALLENGE 2! Write a subsetting command to return the values in x that are greater than 4 and less than 7

Challenge 3

Subset lists

Day 3

https://bookdown.org/yihui/rmarkdown-cookbook/

Rmarkdown

But why?

chunk refresher

new chunk: Cmd + option + i or cntrl + alt + i (windows!)

another reason to name your chunks: chunk names become figure file names

Chunk Options:

  • Use echo=FALSE to avoid having the code itself shown.
  • Use results="hide" to avoid having any results printed.
  • Use eval=FALSE to have the code shown but not evaluated.
  • Use warning=FALSE and message=FALSE to hide any warnings or messages produced.
  • Use fig.height and fig.width to control the size of the figures produced (in inches).

More Markdown

Rmarkdown Cheatsheet: https://rmarkdown.rstudio.com/lesson-15.html

Headers

H1

H2

H3

H4

Bold

Italic

Bold and Italic

  • bullet-points
  1. numbered lists

subscripts:) and super scripts:)

links: text to show

equations : \(E = mc^2\)

looks like code

longer looks like code

Images

  • from your computer

  • from the internet

Tables

Or for a dataframe:

also check out kableExtra package: https://bookdown.org/yihui/rmarkdown-cookbook/kableextra.html

Knit!

Shortcut: ctrl/cmd + shift + k

Rmarkdown as a Github Page

Example: https://maggimars.github.io/OctobeR/october_r_course.html

Lets do it!

Navigate to github.com and sign in if you aren’t already

click repositories

click new

Make a new repo - name it something nice - do not initiate a read me or anything else - click create

In the terminal:

git branch -M main
git remote add origin https://github.com/maggimars/test.git
git push -u origin main

Then we will add our knited html (and anything else you want!)

git add october_r_course.html
git commit -m "added the knitted html file"
git push

then settings > Pages

Change branch to main and save.

Your knitted Rmarkdown is now a website!!!!